/**
 * 车辆详情对话框（可用于添加和修改对话框）
 */
var bankcardInfoDlg = {
    data: {
        cardId: "",
        userId: "",
        cardName: "",
        cardPhone: "",
        cardNumber: "",
        cardPassword: "",
        cardMoney: ""
    }
};

bankcardInfoDlg.validateForm = function () {

    var data = bankcardInfoDlg.data;

    if (!data.cardName) {
        return "请输入姓名";
    }
    if (!data.cardPhone) {
        return "请输入联系电话";
    }
    if (!data.cardPassword) {
        return "请输入初始密码";
    }
    return true;
};


/**
 * 关闭此对话框
 */
bankcardInfoDlg.close = function () {
    parent.layer.close(window.parent.bankcard.layerIndex);
};

/**
 * 提交添加银行卡
 */
bankcardInfoDlg.addSubmit = function () {

    var ajax = new $ax(Feng.ctxPath + "/bankcard/add", function (data) {
        window.parent.Feng.success("添加成功!");
        parent.location.reload();
        bankcardInfoDlg.close();
    }, function (data) {
        window.parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.data);
    ajax.start();
};

$(function () {

    bankcardInfoDlg.app = new Vue({
        el: '#bankcardForm',
        data: bankcardInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            //表单验证
            ensure: function () {
                var result = bankcardInfoDlg.validateForm();
                if (result === true) {
                    bankcardInfoDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                bankcardInfoDlg.close();
            }
        }
    });
});
